package com.itheima.web.usermanager;

import cn.hutool.core.util.ArrayUtil;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import com.itheima.vo.MovementVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
import java.util.Map;

@Component
public class MovementManager{

    @DubboReference
    private MovementService movementService;

    //动态复审通过
    public ResponseEntity recheckPass( String[] ids) {
        //遍历
        if (ArrayUtil.isNotEmpty(ids)) {
            for (String id : ids) {
                //调用rpc查询动态详情
                Movement movement = movementService.findByid(new ObjectId(id));
                movement.setState(1);
                //修改数据库
                movementService.updateState(movement);
            }
        }
        Map<String,Object> map = new HashMap<>();
        map.put("message","ok" );
        return ResponseEntity.ok(map);
    }
    //动态复审拒绝
    public ResponseEntity reject(String[] ids) {
        //遍历
        if (ArrayUtil.isNotEmpty(ids)) {
            for (String id : ids) {
                //调用rpc查询动态详情
                Movement movement = movementService.findByid(new ObjectId(id));
                movement.setState(2);
                //修改数据库
                movementService.updateState(movement);
            }
        }
        Map<String,Object> map = new HashMap<>();
        map.put("message","ok" );
        return ResponseEntity.ok(map);
    }
}
